<template>
  <div>
    <el-button type="primary" size="small" icon="el-icon-check" @click="createNewAllocate()" >生成调拨单</el-button>
    <el-button type="info" size="small" icon="el-icon-back" @click="gotoList">&nbsp;返&nbsp;回&nbsp;</el-button>
  </div>
  <el-table :data="detailList" class="detail" height="calc(130vh - 325px)" >
    <el-table-column label="No." width="60" align="right" type="index"></el-table-column>
    <el-table-column label="调拨单号" width="160" prop="allocateNo"></el-table-column>
    <el-table-column label="物料编码" width="160" prop="goodsNo"></el-table-column>
    <el-table-column label="物料名称" width="160" prop="goodsName"></el-table-column>
    <el-table-column label="调拨数量" width="80" prop="skuCount"></el-table-column>
    <el-table-column label="新工厂库存" width="80" prop="xinCount"></el-table-column>
    <el-table-column label="新工厂使用" width="80" prop="xinUse"></el-table-column>
    <el-table-column label="委外仓库存" width="80" prop="weiCount"></el-table-column>
    <el-table-column label="委外仓使用" width="80" prop="weiUse"></el-table-column>
    <el-table-column label="老工厂库存" width="80" prop="daCount"></el-table-column>
    <el-table-column label="老工厂使用" width="80" prop="daUse"></el-table-column>

    <el-table-column label="备注" width="250" align="rowRemark">

    </el-table-column>


  </el-table>
</template>

<script>

export default {

  data() {
    return {
      detailList: []
    }
  },
  async mounted() {
    const billNoListParam = this.$route.query.billNoList;
    if (billNoListParam) {
      try {
        // 解析回数组
        const billNoList = JSON.parse(decodeURIComponent(billNoListParam));
        return this.getBill(billNoList)
      } catch (error) {

      }
    }
  },
  methods: {
    gotoList() {
      return this.$router.push('/yexiang/innersettorderListYX')
    },
    //生成新的调拨单
    async createNewAllocate(){
      try {
        await this.$confirm(`确定生成调拨单吗`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
      } catch(e) {
        return
      }
      this.loading = true
      try {
        let res = await this.callApi('create_allocation_by_allocation', { detailList: this.detailList })
        if (!res.res) {
          return
        }
        this.$message.success(`生成成功`)

        this.gotoList()
      } finally {
        this.loading = false
      }
    },
    async getBill(billNoList) {
      this.loading = true
      try {
        let res = await this.callApi('get_bainian_allocation_detail', { billNoList })
        if (res.res) {
          console.log(res)
          this.detailList = res.datalist || []

        }
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>

</style>